#pragma once
#include <iostream>
#include <vector>
using namespace std;

namespace MY
{
	template<size_t N>
	class bitset
	{
	public:
		bitset()
		{
			bs.resize(N / 32 + 1, 0);
		}
		void set(size_t x)
		{
			size_t i = x / 32;
			size_t j = x % 32;

			bs[i] |= (1 << j);
		}
		void reset(size_t x)
		{
			size_t i = x / 32;
			size_t j = x % 32;

			bs[i] &= (~(1 << j));
		}
		bool test(size_t x)
		{
			size_t i = x / 32;
			size_t j = x % 32;

			return bs[i] & (1 << j);
		}
	private:
		vector<size_t> bs;
	};

	template<size_t N>
	class twobitset
	{
	public:
		void set(size_t x)
		{
			bool bt1 = bs1.test(x);
			bool bt2 = bs2.test(x);

			if (!bt1 && !bt2)
			{
				bs2.set(x);
			}
			else if (!bt1 && bt2)
			{
				bs2.reset(x);
				bs1.set(x);
			}
			else if (bt1 && !bt2)
			{
				bs2.set(x);
			}
		}
		void reset(size_t x)
		{
			bool bt1 = bs1.test(x);
			bool bt2 = bs2.test(x);

			if (!bt1 && bt2)
			{
				bs2.reset(x);
			}
			else if (bt1 && !bt2)
			{
				bs1.reset(x);
				bs2.set(x);
			}
			else if (bt1 && bt2)
			{
				bs2.reset(x);
			}
		}
		int get_count(size_t x)
		{
			bool bt1 = bs1.test(x);
			bool bt2 = bs2.test(x);

			if (!bt1 && !bt2)
			{
				return 0;
			}
			else if (!bt1 && bt2)
			{
				return 1;
			}
			else if (bt1 && !bt2)
			{
				return 2;
			}
			else {
				return 3;
			}
		}
	private:
		bitset<N> bs1;
		bitset<N> bs2;
	};
}